<?php
require_once('App-Top.php');
require_once('Authorizer.php');
require_once('GenFunctions.php');
require_once('DBConfigQuery.php');
require_once('../config.inc.php');
require_once('../Validation.php');

// Check if it is Member Mng
if (isset($_SESSION['SESS_USER_TYPE'])) {
    if (!isUserType_Members($_SESSION['SESS_USER_TYPE'])) {
        header("Location: AdminIndex.php");
        exit();
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Member Edit</title>
        <link href="StyleControl.css" rel="stylesheet" type="text/css" />
    </head>
    <body>

        <div id="sidebar">
            <h3>Reports</h3>
            <ul>
                <li><a href="#">Gate List</a></li>
                <li><a href="#">Members List</a></li>
            </ul>


            <?php
            require_once('MenuAdmin.php');
            ?>
        </div>

        <div id="mainbody">
            <h1>Member Edition</h1> <br />

            <table summary="Edit Member Information" class="TSoft">

                <tr>
                    <td class="THeader"><a href="AdminMemberEdit.php?qorder=usern">UserName</a></td>
                    <td class="THeader"><a href="AdminMemberEdit.php?qorder=fname">First Name</a></td>
                    <td class="THeader"><a href="AdminMemberEdit.php?qorder=lname">Last Name</a></td>
                    <td class="THeader">Email</td>
                    <td class="THeader">Cell Phone</td>
                    <td class="THeader">Home Phone</td>
                    <td class="THeader">Office Phone</td>
                    <td class="THeader"><a href="AdminMemberEdit.php?qorder=status">Status</a></td>
                    <td class="THeader">Edit</td>
                </tr>

            <?php

            $queryOrdering = "M.LastName";
            if (isset($_GET['qorder'])) {
                switch(strtolower($_GET['qorder'])){
                    case 'fname':
                        $queryOrdering = "M.FirstName";
                        break;

                    case 'status':
                        $queryOrdering = "M.Status";
                        break;

                    case 'usern':
                        $queryOrdering = "M.MemberId";
                        break;

                    default:
                        $queryOrdering = "M.LastName";
                        break;
                }
            }


            $q = sprintf($Q_UserNameLnameEmailCellHomeOfficeStat_Ordering, $queryOrdering);
            $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

            //Check whether the query was successful or not
            if ($r) {

                while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){

                    echo "<tr>";
                    foreach ($row as $value) {
                        echo "<td class='TBody'>" . $value . "</td>";
                    }
                    echo '<td class="TBody"><a href="AdminMemberEditUser.php?membid=' . $row['MemberId'] . '">Edit</a></td>';
                    echo "</tr>";
                }
                mysqli_free_result($r);
                mysqli_close($dbc);
            } else {
                // Free DB
                mysqli_close($dbc);
                die("Query failed");
            }

            ?>


            </table>
            

        </div>

    </body>
</html>
<?php

    require_once('App-End.php');
?>

<!-- Designed: Jose Trujillo - 2011 -->